package com.mk.admin.service.impl;

import com.mk.admin.mapper.RoleMapper;
import com.mk.admin.model.ResultDto;
import com.mk.admin.model.entity.RoleEntity;
import com.mk.admin.model.query.RoleQuery;
import com.mk.admin.model.vo.RoleVo;
import com.mk.admin.service.RoleService;
import com.mk.admin.util.JSONCopy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleMapper roleMapper;

    @Override
    public ResultDto add(RoleVo vo) {
        RoleEntity entity = JSONCopy.copy(vo, RoleEntity.class);
        return ResultDto.data(roleMapper.insert(entity));
    }

    @Override
    public ResultDto update(RoleVo vo) {
        RoleEntity entity = JSONCopy.copy(vo, RoleEntity.class);
        return ResultDto.data(roleMapper.updateById(entity));
    }

    @Override
    public ResultDto delete(int id) {
        return ResultDto.data(roleMapper.deleteById(id));
    }

    @Override
    public ResultDto status(int id) {
        return ResultDto.data(roleMapper.status(id));
    }

    @Override
    public ResultDto select(RoleQuery query) {
        RoleEntity entity = JSONCopy.copy(query, RoleEntity.class);
        return ResultDto.data(roleMapper.count(entity), roleMapper.select(entity));
    }
}
